package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 返回前台信息的控制类
 */
@RestController
@CrossOrigin
@RequestMapping("/eduservice/indexfront")
public class IndexFromController {
    private EduCourseService eduCourseService;
    @Autowired
    public void setEduCourseService(EduCourseService eduCourseService) {
        this.eduCourseService = eduCourseService;
    }

    private EduTeacherService eduTeacherService;
    @Autowired
    public void setEduTeacherService(EduTeacherService eduTeacherService) {
        this.eduTeacherService = eduTeacherService;
    }

    // 获取主页信息.查询前八条热门课程信息,前四条名师信息
    @GetMapping("/indexInfo")
    public R indexInfo(){
        // 查询前八条热门课程
        List<EduCourse> courses = eduCourseService.getHotCourse();

        // 查询前四条名师信息
        List<EduTeacher> teachers = eduTeacherService.getHotTeacher();

        // 返回信息
        return R.ok().data("courseList",courses).data("teacherList",teachers);
    }
}
